﻿@{
    ViewBag.Title = "修改图书信息";
    Layout = "~/Views/Shared/_Layout.cshtml";
    BookInfo BookInfo = ViewBag.BookInfo;
}
@using Model;
<script>
    $(function () {
        $("[href='/BooksManage/BooksInfo']").parent("li").addClass("active").parent().parent("div").addClass("collapse in").parent("li").addClass("active");
    });
</script>
<div class="card">
    <form id="EditBookInfo" class="form-horizontal" method="post" novalidate="novalidate">
        <input type="hidden" name="BookID" value="@BookInfo.BookID">
        <div class="content">
            <legend>图书信息</legend>

            <fieldset>
                <div class="form-group">
                    <label class="col-sm-2 control-label">图书名称</label>
                    <div class="col-sm-6" style="width: 300px">
                        <input class="form-control" type="text" name="BookName" placeholder="请输入1-50字名称" value="@BookInfo.BookName">
                    </div>
                    <label class="col-sm-2 control-label">图书类型</label>
                    <div class="col-sm-6" style="width: 300px">
                        <div class="btn-group bootstrap-select">
                            <select name="TypeID" class="selectpicker" data-title="请选择" data-style="btn-default btn-block" data-menu-style="dropdown-blue" tabindex="-98" size="5">
                                @foreach (var item in ViewBag.BookTypeList)
                                {
                                    if (item.TypeID==BookInfo.TypeID)
                                    {
                                        <option value="@item.TypeID" selected="selected">@item.TypeName</option>
                                    }
                                    else
                                    {
                                        <option value="@item.TypeID">@item.TypeName</option>
                                    }
                                }

                            </select>
                        </div>
                    </div>
                </div>
            </fieldset>

            <fieldset>
                <div class="form-group">
                    <label class="col-sm-2 control-label">图书编号</label>
                    <div class="col-sm-6" style="width: 300px">
                        <input class="form-control" type="text" name="BookNum" placeholder="请输入图书编号(ISBN)" value="@BookInfo.BookNum">
                    </div>
                    <label class="col-sm-2 control-label">作  者</label>
                    <div class="col-sm-6" style="width: 300px">
                        <input class="form-control" type="text" name="Author" placeholder="请输入1-50字名称" value="@BookInfo.Author">
                    </div>
                </div>
            </fieldset>

            <fieldset>
                <div class="form-group">
                    <label class="col-sm-2 control-label">出版社</label>
                    <div class="col-sm-6" style="width: 300px">
                        <input class="form-control" type="text" name="Pubishing" placeholder="请输入出版社字名称" value="@BookInfo.Pubishing">
                    </div>
                    <label class="col-sm-2 control-label">价  格</label>
                    <div class="col-sm-6" style="width: 300px">
                        <input class="form-control" type="text" name="PresentPrice" placeholder="请输入价格" value="@BookInfo.PresentPrice">
                    </div>
                </div>
            </fieldset>

            <fieldset>
                <div class="form-group">
                    <label class="col-sm-2 control-label">出版日期</label>
                    <div class="col-sm-6" style="width: 300px">
                        <div class="control-group">
                            <div class="controls">
                                <div class="input-prepend input-group">
                                    <span class="add-on input-group-addon"><i class="glyphicon glyphicon-calendar fa fa-calendar"></i></span>
                                    <input type="text" readonly="" style="width: 200px" name="PublicaDate" class="form-control active birthday" value="@BookInfo.PublicaDate">
                                </div>
                            </div>
                        </div>
                    </div>                
                </div>
            </fieldset>
            <fieldset>
                <div class="form-group">
                    <label class="col-sm-2 control-label">简  介</label>
                    <div class="col-sm-6" style="width: 800px">
                        <textarea class="form-control" name="BookDesc" placeholder="请输入200字以内简介">@BookInfo.BookDesc</textarea>
                    </div>
                </div>
            </fieldset>
            <fieldset>
                <div class="form-group">
                    <label class="col-sm-2 control-label">详细介绍</label>
                    <div class="col-sm-6" style="width: 800px">
                        <textarea class="form-control" name="BookDescMax" placeholder="输入详细介绍" style="height:100px">@BookInfo.BookDescMax</textarea>
                    </div>
                </div>
            </fieldset>
            <fieldset>
                <div class="form-group">
                    <label class="col-sm-2 control-label">前  言</label>
                    <div class="col-sm-6" style="width: 800px">
                        <textarea class="form-control" name="Preface" placeholder="请输入200字以内前言" style="height:100px">@BookInfo.Preface</textarea>
                    </div>
                </div>
            </fieldset>
            <fieldset>
                <div class="form-group">
                    <label class="col-sm-2 control-label">作者介绍</label>
                    <div class="col-sm-6" style="width: 800px">
                        <textarea class="form-control" name="AuthorDesc" placeholder="输入作者介绍" style="height:100px">@BookInfo.AuthorDesc</textarea>
                    </div>
                </div>
            </fieldset>
            <script type="text/javascript">
                $(document).ready(function () {
                    $('.birthday').daterangepicker({ singleDatePicker: true }, function (start, end, label) {
                        console.log(start.toISOString(), end.toISOString(), label);
                    });
                });
            </script>
        </div>

    </form>
    <div class="footer text-center">
        <button id="submit" type="button" class="btn btn-info btn-fill" onclick="showSwal('submit')">保存 </button>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <button id="cloes" type="button" class="btn btn-info btn-fill" onclick="location.href='/BooksManage/BooksInfo'">返回 </button>
    </div>
</div>
<script>
    $(function () {
    });
    //提交表单
    function showSwal(type) {
        if (type == 'submit') {
            swal({
                title: "确定提交吗?",
                text: "",
                type: "warning",
                showCancelButton: true,
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                closeOnConfirm: false,
                closeOnCancel: false
            }, function (isConfirm) {
                if (isConfirm) {
                    $.ajax({
                        cache: true,
                        type: "POST",
                        url: '/BooksManage/EditBookInfo',
                        data: $('#EditBookInfo').serialize(),// 你的formid
                        async: false,
                        error: function (request) {
                            swal("错误", "", "error");
                        },
                        success: function (data) {
                            if (data == "修改成功") {
                                swal(data, "", "success");
                            } else {
                                swal(data, "", "error");
                            }
                        }
                    });
                } else {
                    swal("取消保存", "", "error");
                }
            });
        }
    }
</script>
